import BASE_URL from './baseUrl.js'

export const request = (config)=>{
	return new Promise((resolve,reject)=>{
		uni.showLoading({
			title:'加载中...',
			mask:true
		});
		uni.request({
			url: BASE_URL + config.url,
			method:config.method || 'GET',
			data:config.data || {},
			timeout:5000,
			success: (res) => {
				if (res.data.code!=20000) {
					uni.showToast({
						title:'数据请求失败',
						icon:'error'
						
					})
				}
				resolve(res);
				uni.hideLoading();
			},
			fail: (err) => {
				uni.showToast({
					title:'接口请求失败',
					icon:'error'
				});
				reject(err);
				uni.hideLoading();
			}
		})
	})
}